package com.yima.baseproj.module.sys.feedback;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yima.baseproj.aop.log.Logging;
import com.yima.baseproj.module.config.utils.PageUtil;
import com.yima.baseproj.module.config.utils.PageVo;
import com.yima.baseproj.module.sys.bill.BillEntity;
import com.yima.baseproj.module.sys.feedback.model.FeedBackSearchModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "反馈管理")
@RequestMapping("/api/sys/feedback")
@RestController
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    @Logging(tags = "反馈管理",value = "查询分页")
    @PreAuthorize("hasAuthority('sys:feedback:findAllByPage')")
    @ApiOperation("查询分页")
    @GetMapping("/findAllByPage")
    public Object findAllByPage(PageVo page, FeedBackSearchModel searchModel) {
        Page<Map> pageData = feedBackService.findAllByPage(PageUtil.initMpPage(page),searchModel);
        return pageData;
    }

    @Logging(tags = "反馈管理",value = "添加")
    @PreAuthorize("hasAuthority('sys:feedback:add')")
    @ApiOperation("添加")
    @PostMapping("/add")
    public void saveUser(@RequestBody @Validated FeedBackEntity customAdmin) {

        feedBackService.add(customAdmin);
    }

    @ApiOperation("根据id查询反馈内容")
    @GetMapping("/findById/{id}")
    public FeedBackEntity findById(@PathVariable int id){
        FeedBackEntity feedBackEntity = feedBackService.findById(id);
        return feedBackEntity;
    }
}
